//
//  UITableView+LFTMCScrollTo.m
//  lofter-mvpcourse-ios
//
//  Created by Thomas Quan on 2017/5/6.
//  Copyright © 2017年 undefined-zola. All rights reserved.
//

#import "UITableView+LFTMCScrollTo.h"

@implementation UITableView (LFTMCScrollTo)

- (void)lftmc_scrollToBottom:(BOOL)animation
{
    if (self.contentSize.height + self.contentInset.top > self.frame.size.height)
    {
        CGPoint offset = CGPointMake(0, self.contentSize.height - self.frame.size.height);
        [self setContentOffset:offset animated:animation];
    }
}

- (void)lftmc_scrollToTop:(BOOL)animation {
    self.scrollsToTop = YES;
    CGPoint offset = CGPointMake(0, 0);
//    [self setContentOffset:CGPointZero animated:animation];
//    [self scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
//    [self scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
//    if ([self numberOfSectionsInTableView:self.tableView] > 0)
    if (self.numberOfSections > 0) {
        NSIndexPath* top = [NSIndexPath indexPathForRow:NSNotFound inSection:0];
        [self scrollToRowAtIndexPath:top atScrollPosition:UITableViewScrollPositionTop animated:YES];
    }
}

//- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;
//- (void)scrollToNearestSelectedRowAtScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;
//[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];

- (void)lftmc_scrollToPosition:(CGFloat)position animation:(BOOL)animation {
    CGPoint offset = CGPointMake(0, self.contentSize.height - self.frame.size.height);
}

- (void)lftmc_scrollToLastPosition:(NSIndexPath *)lastIndexPath animation:(BOOL)animation {
    if (lastIndexPath) {
        [self scrollToRowAtIndexPath:lastIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:animation];
    }
}


@end
